package com.atelier.plugin.database.ui;

import com.atelier.plugin.database.domain.DatabaseType;
import com.atelier.plugin.database.util.ConnectionUtil;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ex.SingleConfigurableEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

public class DataSourceSettingEditor extends SingleConfigurableEditor {
    private DatabaseType databaseType;

    public DatabaseType getDatabaseType() {
        return databaseType;
    }

    public void setDatabaseType(DatabaseType databaseType) {
        this.databaseType = databaseType;
    }

    public DataSourceSettingEditor(@Nullable Project project, @NotNull Configurable configurable, String dimensionKey, boolean showApplyButton, @NotNull IdeModalityType ideModalityType) {
        super(project, configurable, dimensionKey, showApplyButton, ideModalityType);
    }

    public DataSourceSettingEditor(@Nullable Project project, Configurable configurable) {
        super(project, configurable);
    }
    public DataSourceSettingEditor(@Nullable Project project, Configurable configurable, DatabaseType databaseType) {

        super(project, configurable);

    }

    /**
     * @return
     */
    @Override
    protected JComponent createCenterPanel() {
        return  DataSourceSettingDialog.getInstance().getRootPane();
    }

    /**
     * @return
     */
    @Override
    public JComponent getContentPanel() {

        JRootPane rootPane = DataSourceSettingDialog.getInstance().getRootPane();
        return rootPane;
    }

    /**
     * @return
     */
    @Override
    public JComponent getPreferredFocusedComponent() {
        JRootPane rootPane = DataSourceSettingDialog.getInstance().getRootPane();
        return rootPane;
    }

    @Override
    public void doCancelAction() {
        super.doCancelAction();

    }

    @Override
    public void dispose() {
        ConnectionUtil.closeConnection();
        super.dispose();
    }

    @Override
    public boolean isOK() {
        return super.isOK();
    }

}
